package cadtoolbox.utils;

import javax.swing.JComboBox;

import org.jfree.chart.ChartMouseEvent;
import org.jfree.chart.ChartMouseListener;
import org.jfree.chart.ChartPanel;

public class MyChartMouseListener implements ChartMouseListener {

	protected boolean isOn = false;
	protected ChartPanel panel;
	protected JComboBox myCombo;
	
	MyChartMouseListener(ChartPanel panel,JComboBox myCombo){
		this.panel = panel;
		this.myCombo = myCombo;
	}
	@Override
	public void chartMouseClicked(ChartMouseEvent arg0) {
		
		if(isOn){
			//Register point
			//TODO: doesn't work if zooming.
			//TODO: also, sould remove existing points that are close enough
			((PlotExpData)panel.getParent()).addPoint(arg0.getTrigger().getX(),arg0.getTrigger().getY(),myCombo.getSelectedIndex());
			
			
			}
		
		panel.getParent().repaint();
	}

	@Override
	public void chartMouseMoved(ChartMouseEvent arg0) {
		// TODO Auto-generated method stub

	}
	
	public void toggle(boolean bool){
		this.isOn = bool;
	}
	
	public boolean isOn(){
		return this.isOn;
	}

}
